use core::mem::MaybeUninit;
use core::slice;

#[repr(align(8))]
pub struct DMABuffer<T, const COUNT: usize> {
    _buf: MaybeUninit<[T; COUNT]>,
}

impl <T, const COUNT: usize> DMABuffer<T, COUNT> {

    pub const fn count(&self) -> u16 {
        COUNT as u16
    }

    pub const fn default() -> Self {
        Self { _buf: MaybeUninit::uninit() }
    }

    pub const fn as_ptr(&self) -> *const T {
        self as *const Self as *const T
    }

    #[inline(always)]
    pub fn as_mut(&mut self) -> &mut[T] {
        unsafe {
            slice::from_raw_parts_mut(
                self as *mut Self as *mut T, 
                COUNT
            )
        }
    }

    pub const fn as_ref(&self) -> &[T] {
        unsafe {
            slice::from_raw_parts(
                self as *const Self as *const T, 
                COUNT
            )
        }
    }
}

